<?php

namespace App\Controller;

use App\GreetingGenerator;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class DefaultController extends AbstractController
{
    /**
     * @Route("/hello/{name?}")
     * @param $name
     * @param $logger LoggerInterface
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function index($name, LoggerInterface $logger, GreetingGenerator $generator)
    {
        $greeting = $generator->getRandomGreeting();
        $logger->info("Saying $greeting to $name!");
        return $this->render('default/index.html.twig', [
            'name' => $name
        ]);
    }

    /**
     * @Route("/api/hello/{name}")
     * @param $name
     * @return \Symfony\Component\HttpFoundation\JsonResponse
     */
    public function apiExample($name)
    {
        return $this->json([
            'name' => $name,
            'symfony' => 'rocks',
        ]);
    }
}